//
//  JFTabBarViewController.m
//  KaKa
//
//  Created by junFung on 15/12/17.
//  Copyright © 2015年 yc. All rights reserved.
//

#import "JFTabBarViewController.h"
#import "JFNavigationController.h"
#import "RecommandController.h"
#import "ForumController.h"
#import "FindCarController.h"
#import "DiscoveryController.h"
#import "MeController.h"
#import "JFTabBar.h"

@interface JFTabBarViewController ()<JFTabBarDelegate>

@end

@implementation JFTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildVC];
    [self setupJTabBar];
}

/** 自定义tabBar*/
- (void)setupJTabBar
{
    JFTabBar *tab = [[JFTabBar alloc] init];
    tab.JFTabBarDelegate = self;
    
    /** 更换系统自带的tabbar*/
    [self setValue:tab forKey:@"tabBar"];
}
#pragma mark --- 添加子视图 ---
- (void)addChildVC
{
    RecommandController *recommand  = [[RecommandController alloc] init];
    MeController *me  = [[MeController alloc] init];
    ForumController *forum = [[ForumController alloc] init];
    DiscoveryController *dy = [[DiscoveryController alloc] init];
    FindCarController *findCar = [[FindCarController alloc] init];
    
    JFNavigationController *navRec  = [[JFNavigationController alloc] initWithRootViewController:recommand];
    JFNavigationController *navFor  = [[JFNavigationController alloc] initWithRootViewController:forum];
    JFNavigationController *navDy   = [[JFNavigationController alloc] initWithRootViewController:dy];
    JFNavigationController *navFind  = [[JFNavigationController alloc] initWithRootViewController:findCar];
    JFNavigationController *navMe   = [[JFNavigationController alloc] initWithRootViewController:me];

    recommand.tabBarItem.image = [UIImage imageNamed:@"tabbarItem_home_normal"];
    recommand.tabBarItem.selectedImage = [self imageWithRenderingMode:@"tabbarItem_home_selected"];
    
    forum.tabBarItem.image = [UIImage imageNamed:@"tabbarItem_message_normal"];
    forum.tabBarItem.selectedImage = [self imageWithRenderingMode:@"tabbarItem_message_selected"];
    
    findCar.tabBarItem.image = [UIImage imageNamed:@"tabbarItem_message_normal"];
    findCar.tabBarItem.selectedImage = [self imageWithRenderingMode:@"tabbarItem_message_selected"];
    
    dy.tabBarItem.image = [UIImage imageNamed:@"tabbarItem_dynamic_normal"];
    dy.tabBarItem.selectedImage = [self imageWithRenderingMode:@"tabbarItem_dynamic_selected"];
    
    me.tabBarItem.image = [UIImage imageNamed:@"tabbarItem_personal_normal"];
    me.tabBarItem.selectedImage = [self imageWithRenderingMode:@"tabbarItem_personal_selected"];
    
    recommand.title = @"推荐";
    forum.title = @"论坛";
    findCar.title = @"找车";
    dy.title = @"动态";
    me.title = @"我";

    [self addChildViewController:navRec];
    [self addChildViewController:navFor];
    [self addChildViewController:navFind];
    [self addChildViewController:navDy];
    [self addChildViewController:navMe];

}

- (UIImage *)imageWithRenderingMode:(NSString *)selectedImage
{
    UIImage *selectedImageName = [UIImage imageNamed:selectedImage];
    return [selectedImageName imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

- (UIImage *)stretchableImageWithLeftCapWidth:(NSString *)name
{
    UIImage *imageName = [UIImage imageNamed:name];
    return [imageName stretchableImageWithLeftCapWidth:imageName.size.width*0.5 topCapHeight:imageName.size.height*0.5];
}
#pragma mark --- JTabBarDelegate ---
- (void)JFTabBar:(JFTabBar *)tabBar onClickButton:(UIButton *)sender
{
    NSLog(@"-----------点击-----------");
}
@end
